#!/bin/bash
name=$(basename $0);

if [[ "$name" == "jarbox" ]];then
    if [[ "$1" == "-i" ]];then
        mkdir /usr/jar>/dev/null 2>/dev/null;
        cp -f $2 /usr/jar/$3.jar
        rm /f /usr/local/bin/$3 2>/dev/null
        ln -s /usr/local/bin/jarbox /usr/local/bin/$3
        echo "[Done] $3 installed"
        exit
    
    else
    echo "name: jarbox (by wanyl)"
    echo "version: 1.0.0"
    echo "install jar method one"
    echo "first step:your jar please put in /usr/jar dirctory.if not have /usr/jar dirctory,you can new one."
    echo "second step:create link this file($0) to /usr/local/bin,and then rename link file in /usr/local/bin."
    echo "install jar method two"
    echo "jarbox -i [source jar file] [install name]"
    exit;
    fi
fi
PATH=$PATH:/usr/jar
jar=$(which ${name}.jar| sed -r 's/^[ \t]+(.*)[ \t]+$//g')

if [ -z "$jar" ];then
    echo "not found $0.jar";
    exit;
fi
java -jar $jar $*